import { defineStore } from "pinia"
import { ref } from "vue"
import API from "@renderer/api"
import { getPlayListDetailApi } from "@renderer/api";
import { songListType } from "./type"
// import { formatTimestamp } from "@renderer/hooks/index";

const { likeApi } = API
export const useLikeStore = defineStore('likeStore', () => {
    const likeSongs = ref([] as any[])
    const likeSongList = ref([] as songListType[])
    const likeAlbumList = ref([] as any[])
    const likeVoiceList = ref([] as any[])
    const likeVideoList = ref([] as any[])
    const uid = ref(Number(localStorage.getItem('USERID') || '0'))
    const playlist = ref([] as any[])

    const getUserSongList = async () => {
        let res: any = await likeApi.getUserSongListApi(uid.value)
        if (res.code === 200) {
            let { userInfo: { nickname } } = JSON.parse(localStorage.getItem('USERINFO') || '{}')
            playlist.value = res.playlist.map((item: any) => {
                if (item.name === nickname + '喜欢的音乐') {
                    getUserLikeSongs(item.id)
                }
                return {
                    ...item
                }
            })
        }
    }
    const getUserLikeSongs = async (id: number) => {
        let { playlist: { tracks } } = await getPlayListDetailApi(id)
        likeSongs.value = tracks.map((item: any) => {
            return {
                ...item
            }
        })
    }
    const getUserLikePlaySongList = async () => {

    }
    const getUserLikePlayAlbum = async () => {

    }
    const getUserLikePlayVoice = async () => {

    }
    const getUserLikePlayVideo = async () => {

    }
    return {
        likeSongs,
        likeSongList,
        likeAlbumList,
        likeVideoList,
        likeVoiceList,
        getUserSongList,
        getUserLikeSongs,
        getUserLikePlaySongList,
        getUserLikePlayAlbum,
        getUserLikePlayVoice,
        getUserLikePlayVideo,
    }
})